import 'dart:convert';
import 'dart:developer';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_shop/components/friend.dart';

class ContainerTask extends StatefulWidget {
  @override
  State<ContainerTask> createState() => _ContainerTaskState();
}

class _ContainerTaskState extends State<ContainerTask> {
  // List<Friend> _friends = [];
  // var url = "https://randomuser.me/api/?results=30";

  // getData() async {
  //   HttpClient httpClient = new HttpClient();
  //   HttpClientRequest request = await httpClient.getUrl(Uri.parse(url));
  //   HttpClientResponse response = await request.close();
  //   var jsonString = await response.transform(utf8.decoder).join();
  //   setState(() {
  //     _friends = Friend.resolve(jsonString);
  //   });
  // }
  List<Widget> _children = [
    ScreenWidget('首页'),
    ScreenWidget('记录'),
    ScreenWidget('个人'),
  ];

  var _currentIndex = 1;
  void onTap(int seleindex) {
    setState(() {
      _currentIndex = seleindex;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('好友列表'),
      ),
      body: _children[_currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _currentIndex,
        onTap: onTap,
        items: [
          BottomNavigationBarItem(icon: Icon(Icons.home), label: '首页'),
          BottomNavigationBarItem(icon: Icon(Icons.receipt), label: '记录'),
          BottomNavigationBarItem(
              icon: Icon(Icons.accessibility), label: '个人中心'),
        ],
      ),
    );
  }
}

class ScreenWidget extends StatelessWidget {
  final String text;
  ScreenWidget(this.text);
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Text(text),
    );
  }
}
